package com.slicktechnologies.client.views.contract;

import com.google.gwt.cell.client.ButtonCell;
import com.google.gwt.cell.client.FieldUpdater;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.TextColumn;
import com.simplesoftwares.client.library.appstructure.SuperTable;
import com.slicktechnologies.shared.SalesLineItem;
import com.slicktechnologies.shared.common.RecievableGoods;
import com.slicktechnologies.shared.common.helperlayer.Config;

public class CustomerParticularTable extends SuperTable<RecievableGoods> {
	TextColumn<RecievableGoods>CustomerParticularName;
	Column<RecievableGoods,String>deleteColumn;
	

	@Override
	public void createTable() {
		createCustomerParticularNameColumn();
		createColumndeleteColumn();
		addFieldUpdater();
		
	}

	@Override
	protected void initializekeyprovider() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void addFieldUpdater() {
		createFieldUpdaterdeleteColumn();
		
	}

	@Override
	public void setEnable(boolean state) {
		for(int i=table.getColumnCount()-1;i>=0;i--)
			table.removeColumn(i);
		if(state==true)
		{
			createCustomerParticularNameColumn();
			createColumndeleteColumn();
			addFieldUpdater();
		}
		else
			createCustomerParticularNameColumn();
		
	}
	
	
	protected void createColumndeleteColumn()
	{
		ButtonCell btnCell= new ButtonCell();
		deleteColumn=new Column<RecievableGoods,String>(btnCell)
				{
			@Override
			public String getValue(RecievableGoods object)
			{
				return  "Delete" ;
			}
				};
				table.addColumn(deleteColumn,"Delete");
	}
	
	
	protected void createCustomerParticularNameColumn()
	{
		CustomerParticularName=new TextColumn<RecievableGoods>() {

			@Override
			public String getValue(RecievableGoods object) {
				// TODO Auto-generated method stub
				return object.getName();
			}
		};
		table.addColumn(CustomerParticularName,"Customer Item");
		
	}
	
	protected void createFieldUpdaterdeleteColumn()
	{
		deleteColumn.setFieldUpdater(new FieldUpdater<RecievableGoods,String>()
				{
			@Override
			public void update(int index,RecievableGoods object,String value)
			{
				getDataprovider().getList().remove(object);

				table.redrawRow(index);
			}
				});
	}

	@Override
	public void applyStyle() {
		// TODO Auto-generated method stub
		
	}

}
